/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package app.actions;

import app.modelo.Libro;
import app.negocio.GestionLibreria;
import app.negocio.ItfzGestionLibreria;
import app.negocio.LibroNoEncontradoException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Johann
 */
public class ConsultarLibroTituloAction extends Action{

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        if (request.getParameter("titulo") != null) {
            ItfzGestionLibreria gestionLibreria = new GestionLibreria();
            try {
                List<Libro> libros = gestionLibreria.consultarTitulo(request.getParameter("titulo"));
                request.setAttribute("libros", libros);
            } catch (LibroNoEncontradoException ex) {
                request.setAttribute("libroNoEncontrado", ex.getMessage());
            }
        }
        
        // 3.- Redirigir a la vista elegida
        return mapping.findForward("ok");
    }
    
    
}
